Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

332
Vistas
$pipeline is not a list (unexpected index: "$group") in Laravel

When the below query is run the results are displayed in mongo shell.

Sample Records

{
    "_id" : ObjectId("587e21df6e79d255011a9c6a"),
    "vendor_id" : "101",
    "subscription_id" : 14,
    "created_at" : ISODate("2017-01-17T13:53:35.272Z")
}
{
    "_id" : ObjectId("587e21df6e79d255011a9c6c"),
    "vendor_id" : "102",
    "subscription_id" : 14,
    "created_at" : ISODate("2017-01-17T13:56:35.272Z")
}

Query

db.user_config.aggregate({$group: 
{
    _id : "$subscription_id", 
    list: 
    { 
        $push:  
        { 
            _id: "$_id", 
            vendor_id: "$vendor_id"
        } 
     }
}})

Results

/* 1 */
{
    "result" : [ 
        {
            "_id" : 14,
            "list" : [ 
                {
                    "_id" : ObjectId("587e21df6e79d255011a9c6a"),
                    "vendor_id" : "user_101"
                }, 
                {
                    "_id" : ObjectId("587e21df6e79d255011a9c6b"),
                    "vendor_id" : "user_101"
                }
            ]
        }
    ],
    "ok" : 1.0000000000000000
}

But when same thing is done through laravel the following error occurs. $pipeline is not a list (unexpected index: "$group")

Below is the laravel code

$configuration_list = UserConfig::raw()->aggregate([
            '$group' => [
                    '_id'    => '$subscription_id',
                    'list'  => ['$push' => 
                     ['_id' => '$_id', 'vendor_id' => '$vendor_id']]
                ]
            ]
        );

Can someone please help me solve this issue..

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

Wrap the aggregation pipeline steps in an array:

$pipeline = [
    [
        '$group' => [
            '_id' => '$subscription_id',
            'list' => [
                '$push' => [
                    '_id' => '$_id', 
                    'vendor_id' => '$vendor_id'
                ]
            ]
        ]
    ]
];
$configuration_list = UserConfig::raw()->aggregate($pipeline);
over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda